package 对象之封装.银行取款类;
//银行取款

import java.util.Scanner;

class text5 {
    public static void main(String[] args) {

        BankCard b1 = new BankCard("张三", "123456", 500);
        b1.printinfo();
        b1.save(1000);
        b1.printinfo();
        b1.get(100);
        b1.printinfo();
    }
}

class BankCard {
    String name;
    String password;
    double money;

    public BankCard(String name, String password, double money) {
        this.name = name;
        this.password = password;
        this.money = money;
    }

    void save(double m) {

        this.money += m;
        System.out.println("成功存入了" + m + "元");
    }

    void get(double m) {
        System.out.println("请输入你的密码：");
        Scanner sc = new Scanner(System.in);
        String password = sc.nextLine();
        if (this.password.equals(password)) {
            if (this.money >= m) {
                this.money -= m;
                System.out.println("成功取款" + m + "元");
            } else {
                System.out.println("取款失败，余额不足");
            }
        } else {
            System.out.println("你输入的密码不正确");
        }
    }

    void printinfo() {
        System.out.println("户名：" + name + ",当前余额：" + money);
    }

}
